import { createRouter, createWebHashHistory } from 'vue-router'
import { BasicLayout, UserLayout, PageView } from '@/layouts'
import { ScissorOutlined } from '@ant-design/icons-vue'

const RouteView = {
  name: 'RouteView',
  render () {
    return (
      <router-view />
    )
  }
}

const asyncRouterMap = [
  {
    path: '/',
    component: BasicLayout,
    redirect: '/advertise',
    meta: {
      title: '首页'
    },
    children: [
      {
        path: '/advertise',
        component: () => import(/* webpackChunkName: "user" */ '@/views/Test.vue'),
        meta: {
          icon: ScissorOutlined,
          title: '测试页'
        }
      },
      {
        path: '/table',
        component: RouteView,
        meta: {
          icon: ScissorOutlined,
          title: '表单表格'
        },
        redirect: '/table/form',
        children: [
          {
            path: '/table/form',
            component: () => import(/* webpackChunkName: "user" */ '@/views/table/form.vue'),
            meta: {
              icon: ScissorOutlined,
              title: '表单页'
            }
          },
          {
            path: '/table/table',
            component: () => import(/* webpackChunkName: "user" */ '@/views/table/table.vue'),
            meta: {
              icon: ScissorOutlined,
              title: '表格页'
            }
          },
        ]
      },
    ]
  },
]
const constantRouterMap = [
  {
    path: '/user',
    component: UserLayout,
    redirect: '/user/login',
    children: [
      {
        path: 'login',
        name: 'login',
        component: () => import(/* webpackChunkName: "user" */ '@/views/auth/Login')
      },
      {
        path: 'register',
        name: 'register',
        component: () => import(/* webpackChunkName: "user" */ '@/views/auth/Register')
      },
      {
        path: 'register-result',
        name: 'registerResult',
        component: () => import(/* webpackChunkName: "user" */ '@/views/auth/RegisterResult')
      },
      {
        path: 'recover',
        name: 'recover',
        component: undefined
      }
    ]
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "fail" */ '@/views/404')
  }
]

const routes = [...asyncRouterMap, ...constantRouterMap]
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router